/**
 * 收货地址相关的接口
 */
import type {PageQueryType, PageResultType} from "@/types/global";
import type {AddressFormType, AddressItemType} from "@/types/user";
import {request} from "@/utils/http";
import type {AddressItemCls} from "@/pagesOrder/types/usercls";

/**
 * 分页获取用户的收货地址
 * @param page
 */
export const getAddressListData = (page: PageQueryType) => {
    return request<PageResultType<AddressItemType>>({
        url: '/delivery-address/page',
        method: "POST",
        data: page
    })
}

/**
 * 获取用户的默认地址
 */
export const getDefaultAddress  = () => {
    return request<AddressItemCls>({
        url: "/delivery-address/default",
        method: "GET"
    })
}
/**
 * 添加收货地址
 * @param form
 */
export const addAddress = (form: AddressFormType) => {
    return request<Boolean>({
        url: "/delivery-address",
        method: "POST",
        data: form
    })
}
export const editAddress = (form: AddressFormType) => {
    return request<Boolean>({
        url: "/delivery-address",
        method: "PUT",
        data: form
    })
}
export const getAddress = (id: number) => {
    return request<AddressFormType>({
        url: "/delivery-address?id=" + id,
        method: "GET",
    })
}